package org.study.apitest;

import org.apache.ibatis.mapping.Environment;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.ibatis.transaction.TransactionFactory;
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
import org.study.apitest.factory.MyDataSourceFactory;
import org.study.mapper.UserFormateMapper;

import javax.sql.DataSource;

/**
 * @program: mybatis-demo-study
 * @description: 不适用xml配置
 * @author: tmz
 * @create: 2020-08-21 13:27
 */
public class SQLFactoryNotByXML {
    public static void main(String[] args) {
        DataSource dataSource = new MyDataSourceFactory().getDataSource();
        TransactionFactory transactionFactory = new JdbcTransactionFactory();
        Environment environment = new Environment("development",transactionFactory,dataSource);
        Configuration configuration = new Configuration(environment);
        configuration.addMapper(UserFormateMapper.class);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
        sqlSessionFactory.openSession().getMapper(UserFormateMapper.class).toString();
    }
}
